package com.smartpro.mis.modular.business.controller;

import com.smartpro.mis.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import com.smartpro.mis.modular.system.model.Constants;
import com.smartpro.mis.modular.business.service.IConstantsService;

/**
 * rest控制器
 *
 * @author fengshuonan
 * @Date 2019-05-07 21:45:23
 */
@Controller
@RequestMapping("/constants")
public class ConstantsController extends BaseController {

    private String PREFIX = "/business/constants/";

    @Autowired
    private IConstantsService constantsService;

    /**
     * 跳转到rest首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "constants.html";
    }

    /**
     * 跳转到添加rest
     */
    @RequestMapping("/constants_add")
    public String constantsAdd() {
        return PREFIX + "constants_add.html";
    }

    /**
     * 跳转到修改rest
     */
    @RequestMapping("/constants_update/{constantsId}")
    public String constantsUpdate(@PathVariable Integer constantsId, Model model) {
        Constants constants = constantsService.selectById(constantsId);
        model.addAttribute("item",constants);
//        LogObjectHolder.me().set(constants);
        return PREFIX + "constants_edit.html";
    }

    /**
     * 获取rest列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return constantsService.selectList(null);
    }

    /**
     * 新增rest
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Constants constants) {
        constantsService.insert(constants);
        return SUCCESS_TIP;
    }

    /**
     * 删除rest
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer constantsId) {
        constantsService.deleteById(constantsId);
        return SUCCESS_TIP;
    }

    /**
     * 修改rest
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Constants constants) {
        constantsService.updateById(constants);
        return SUCCESS_TIP;
    }

    /**
     * rest详情
     */
    @RequestMapping(value = "/detail/{constantsId}")
    @ResponseBody
    public Object detail(@PathVariable("constantsId") Integer constantsId) {
        return constantsService.selectById(constantsId);
    }
}
